#ifndef _MESH_H
#define _MESH_H

#include <string>
#include <vector>
#include <map>

#include <GL/glew.h>
#include <assimp/Importer.hpp> // C++ importer interface
#include <assimp/scene.h>       // Output data structure
#include <assimp/postprocess.h> // Post processing flags
#include <assert.h>

#include "Vertex.h"
#include "Texture.h"
#include "Logger.h"
#include "StringUtils.h"

#ifdef GALLIUMENGINE_DLL 
#define GALLIUMENGINE_API __declspec( dllexport )
#else
#define GALLIUMENGINE_API __declspec( dllimport )
#endif

namespace GalliumEngine
{
	class Mesh
	{
	public:
		GALLIUMENGINE_API Mesh();
		GALLIUMENGINE_API ~Mesh();
		GALLIUMENGINE_API bool loadMesh(const std::string& Filename);
		GALLIUMENGINE_API void draw();

	private:
		bool initFromScene(const aiScene* pScene, const std::string& _filename);
		void initMesh(unsigned int Index, const aiMesh* paiMesh);
		bool initMaterials(const aiScene* pScene, const std::string& _filename);
		void clear();

	#define INVALID_MATERIAL 0xFFFFFFFF

		struct MeshEntry 
		{
			MeshEntry();
			~MeshEntry();

			void init(const std::vector<Vertex>& _vertices,
			const std::vector<unsigned int>& _indices);

			GLuint vbo;
			GLuint ibo;
			unsigned int numIndices;
			unsigned int materialIndex;
		};

		std::vector<MeshEntry> entries;
		std::vector<Texture*> textures;
	};
}

#endif
